package com.dgut.courses_selecting_sys.exception;

import com.dgut.courses_selecting_sys.entity.AjaxResult;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public AjaxResult Handler(Exception e) {
        return AjaxResult.error(e.getMessage());
    }

    @ExceptionHandler(value = UnauthorizedException.class)
    public AjaxResult processUnauthenticatedException(HttpServletRequest request, UnauthorizedException e) {
        return AjaxResult.error("没有权限访问");
    }


}
